package com.study.jdbc.wrapper;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;

import javax.sql.DataSource;

/**
* @Name: ConnectionInvocationHandler
* @Description: Connection接口实现类的代理实例
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-18 下午3:00:21 
* @Version: V1.0
 */
public class ConnectionInvocationHandler implements InvocationHandler {
	
	private Connection con ;
	private DataSource dataSource ;
	
	public ConnectionInvocationHandler(Connection con, DataSource dataSource) {
		this.con = con;
		this.dataSource = dataSource;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		if("close".equals(method.getName())) {
			return dataSource.getConnection() ;
		} else {
			return method.invoke(con, args) ;
		}
	}
	
	

}
